//
//  PlayeViewController.m
//  A Learning Walk
//
//  Created by dllo on 16/6/18.
//  Copyright © 2016年 战斗民族. All rights reserved.
//

#import "PlayeViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface PlayeViewController ()

@property(nonatomic, strong)AVPlayer *videoPlayer;
@property(nonatomic, strong)AVPlayerLayer *layer;
@property(nonatomic, strong)UIView *myView;

@end

@implementation PlayeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self creatBo];
    
    // Do any additional setup after loading the view.
}
-(void)creatBo{
    
    NSURL *url = [NSURL URLWithString:_model.mp4_url];
    //构造AVPlayerItem对象
    AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:url];
    //初始化player
    self.videoPlayer = [[AVPlayer alloc] initWithPlayerItem:item];
    //到这里还没有画面,我们还需要一个AVPlayerLayer对象
    self.layer = [AVPlayerLayer playerLayerWithPlayer:self.videoPlayer];
    self.layer.frame = CGRectMake(0, 100, self.view.frame.size.width, 500);
    self.layer.videoGravity = AVLayerVideoGravityResizeAspect;//让其居中显示
    //添加到屏幕上显示
    [self.view.layer addSublayer:self.layer];
    
    self.myView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 500)];
    self.view.dk_backgroundColorPicker = DKColorPickerWithRGB(0xF0FFF0, 0x4F4F4F);
    [self.view addSubview:self.myView];
    
    
     [self.videoPlayer play];
}


-(void)setModel:(videoModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    _model = model;
//    self.str = _model.mp4_url;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
